import 'package:flutter/cupertino.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';

class RefreshHeaderView extends CustomHeader {

  RefreshHeaderView({Key? key})
      : super(key: key, builder: (BuildContext context, RefreshStatus? mode) {
    Widget body;
    if (mode == RefreshStatus.idle || mode == RefreshStatus.canRefresh) {
      body = Container(
        width: double.infinity,
        padding: const EdgeInsets.only(bottom: 20),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Image.asset('assets/images/common/pull_down_refresh.png', width: 9, height: 23,),
            const SizedBox(width: 20),
            const Text('下拉可以刷新',
                style: TextStyle(color: Color(0xFF707070), fontSize: 12))
          ],
        ),
      );
    } else if (mode == RefreshStatus.refreshing) {
      body = const Padding(
        padding: EdgeInsets.only(bottom: 20),
        child: CupertinoActivityIndicator(),
      );
    } else if (mode == RefreshStatus.completed) {
      body = Container(
        width: double.infinity,
        alignment: Alignment.bottomCenter,
        padding: const EdgeInsets.only(bottom: 20),
        child: const Text('加载完成~',
            style: TextStyle(color: Color(0xFF707070), fontSize: 12)),
      );
    } else {
      body = const Text("下拉刷新");
    }
    return SizedBox(
      height: 55.0,
      child: Center(child: body),
    );
  });
}